package com.liwei.lwmail.elasticsearch.thread;

import java.util.concurrent.*;

public class ThreadTest {

    public static ExecutorService service = Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main......start......");
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,
                200,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100000),//默认是Integer的最大值,一般自己定制数量
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());//丢弃新来的任务

//        Executors.newCachedThreadPool();core=0,都可回收
//        Executors.newFixedThreadPool(10);固定线程数,都不可回收
//        Executors.newScheduledThreadPool(10);定时任务线程池
//        Executors.newSingleThreadExecutor();单线程的线程池

        System.out.println("main......stop......");
    }

    public static class Callable01 implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("当前线程结果："+i);
            return i;
        }
    }

    public static class Runnable01 implements Runnable {
        @Override
        public void run() {
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("当前线程结果："+i);
        }
    }
}
